package org.codingeasy.hotbean.web;

import javax.validation.constraints.NotNull;
import org.codingeasy.hotbean.HotBeanContext;
import org.codingeasy.hotbean.vo.HotBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 热bean管理  
* @author : KangNing Hu
*/
@RequestMapping("/hotBean")
@RestController
@Validated
public class HotBeanController {


  @Autowired
  private HotBeanContext hotBeanContext;

  @PostMapping("/register")
  public String register(@RequestBody HotBean hotBean){
    hotBeanContext.register(hotBean.getClassName() , hotBean.getCode());
    return "注册成功";
  }



  @DeleteMapping("/remove")
  public String remove(@NotNull String className){
    hotBeanContext.remove(className);
    return "移除成功";
  }

}
